package kyssion.leetcode.num151_200;

public class code198_打家劫舍 {
    public static void main(String[] args) {
        System.out.println(new code198_打家劫舍().rob(
                new int[]{
                        2,1,1,2
                }
        ));
    }
    public int rob(int[] nums) {
        if (nums.length == 0) {
            return 0;
        }
        if(nums.length==1){
            return nums[0];
        }
        if(nums.length==2){
            return Math.max(nums[0],nums[1]);
        }
        nums[1] = Math.max(nums[0],nums[1]);
        for (int a = 2; a < nums.length; a++) {
            nums[a]  = Math.max(nums[a-1],nums[a-2]+nums[a]);
        }
        return nums[nums.length - 1];
    }
}
